package com.yingside.annotation.login;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

public class AnnotationReflection {
    public static void main(String[] args) {

        try {
            Class<?> clz = Class.forName("com.yingside.annotation.login.LoginTest");
            Method method = clz.getDeclaredMethod("login");

            //判断方法上是否有某个类型的注解
            boolean flag = method.isAnnotationPresent(Login.class);

            if(flag){
                System.out.println("方法上面有@Login注解");

                Annotation[] annotations = method.getAnnotations();

                for (Annotation a:annotations) {
                    if(a != null && a instanceof Login){
                        String username = ((Login) a).username();
                        String password = ((Login) a).password();

                        System.out.println(username + "  " + password);
                    }
                }


            }
            else{
                System.out.println("方法上面没有@Login注解");
            }




        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }


    }
}
